﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.Serialization;

public abstract class  ViewControllerLoadAnimation : MonoBehaviour 
{
    public bool inShowAnim;
    public bool inHideAnim;
    public bool inLoadingAnim;
   
/*    Action m_OnShowEnd;
    Action m_OnInLoadingEnd;*/
    ViewController m_CurViewController;
    public ViewController CurViewController { get { return m_CurViewController; } }

    protected virtual void OnDestroy()
    {
        //m_OnShowEnd = null;
        //m_OnInLoadingEnd = null;
    }

    public void PlayShowAnimation(ViewController controller, Action onEnd)
    {
        inShowAnim = true;
        m_CurViewController = controller;
        _PlayShowAnim(controller, ()=>
        {
            inShowAnim = false;
            onEnd?.Invoke();
        });
    }


    public void PlayInLoadingAnimation(Action onEnd)
    {
        inLoadingAnim = true;
        _PlayInLoadingAnim(()=>
        {
            inLoadingAnim = false;
            onEnd?.Invoke();
        });
    }
    

    public void PlayHideAnimation(Action onEnd)
    {
        inHideAnim = true;
        
        _PlayHideAnim(()=>
            {
                inHideAnim = false;

                if (onEnd != null)
                    onEnd();
            }
        );
    }

    protected abstract void _PlayShowAnim(ViewController controller, Action onEnd);
    protected abstract void _PlayInLoadingAnim(Action onEnd);
    protected abstract void _PlayHideAnim(Action onEnd);




}